﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using Obsidian.Utils;

namespace Oak.Core.Data
{
    public class SqlTextLoader
    {

        private static readonly string SQL_TEXT_PATH = RuntimeUtil.BinPath + "\\sql\\{0}.sql";
        private static Dictionary<string, string> dictSqlText = new Dictionary<string, string>();

        public static string Get(string name)
        {
            string sqlText;
            if (dictSqlText.TryGetValue(name, out sqlText))
                return sqlText;

            string path = String.Format(SQL_TEXT_PATH, name);
            if (!File.Exists(path))
                throw new Exception(String.Format("SQL文件：{0}不存在!", name));

            sqlText = IOUtil.ReadTextFromFile(path, "utf-8");
            dictSqlText[name] = sqlText;
            return sqlText;
        }

    }
}
